package HuaweiOD;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.util.Arrays;
import java.util.Map;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class 堆排序 {
    public static void main(String[] args) throws Exception {
        int[] arr = {9, 8, 7, 6, 5, 4, 3, 2, 1};
        sort(arr);
        System.out.println(Arrays.toString(arr));
        Son.st();
        Father.st();
        Father father = new Father();
        father.sout();
        Father father1 = new Son();
        father1.sout();
        Son son = new Son();
        son.sout();

        System.out.println(father1 instanceof Son);
        System.out.println(father1 instanceof Father);
        System.out.println(father instanceof Son);

        System.out.println(father.a);
        System.out.println(father1.a);
        System.out.println(son.a);
        
        new ThreadPoolExecutor(2,3, 10, TimeUnit.MINUTES, new LinkedBlockingQueue<>()   ,new ThreadPoolExecutor.AbortPolicy());
    }

    public static void sort(int[] arr) {
        for (int i = arr.length / 2 - 1; i >= 0; i--) {
            adjustHeap(arr, i, arr.length);
        }

        for (int i = arr.length - 1; i >= 0; i--) {
            swap(arr, 0, i);
            adjustHeap(arr, 0, i);
        }
    }

    public static void adjustHeap(int[] arr, int i, int len) {
        int tmp = arr[i];
        for (int k = 2 * i + 1; k < len; k = k * 2 + 1) {
            if (k + 1 < len && arr[k] < arr[k + 1]) {
                k++;
            }
            if (arr[k] > tmp) {
                arr[i] = arr[k];
                i = k;
            } else {
                break;
            }
        }
        arr[i] = tmp;
    }

    public static void swap(int[] arr, int a, int b) {
        int temp = arr[a];
        arr[a] = arr[b];
        arr[b] = temp;
    }
}

class Father{
    public int a = 0;
    public static void st(){
        System.out.println("father static method");
    }
    static {
        System.out.println("father static");
    }
    public Father(){
        System.out.println("father create");
    }
    public void sout() throws Exception{
        System.out.println("father");
    }
}


class Son extends Father{
    public int a = 1;
    static {
        System.out.println("son static");
    }
    public static void st(){
        System.out.println("son static method");
    }
    public Son(){
        System.out.println("son create");
    }
    public void sout() throws Exception{
        System.out.println("son");
    }
}
